********************************************************************************
*
*   FILE: MASTER.do
*
********************************************************************************

********************************************************************************
*
**# 	Define Key User Globals
*
********************************************************************************

* 	Global below stores location of project data folder on your local PC:

gl DIRECTORY 	= "~/Dropbox/Nashville Study (Emily and Aria) - Take 2/REPLICATION"

gl DATA     	= "${DIRECTORY}/DATA"

gl CODE     	= "${DIRECTORY}/CODE"

cap mkdir 		  "${DIRECTORY}/OUTPUT"

gl OUTPUT     	= "${DIRECTORY}/OUTPUT"

* 	Erase any existing files in /OUTPUT:

local outputs: dir "${OUTPUT}" files "*"

foreach output of local outputs {
        rm `output'
}

********************************************************************************
*
**# 	Confirm SSC Packages are Installed
*
********************************************************************************

*	Estimation and descriptive output-related packages

adoupdate reghdfe require ftools, update

*	Output-related packages

adoupdate estout coefplot, update
	
********************************************************************************
*
**#   	Set Seeds
*
********************************************************************************

set seed 		121184

set sortseed 	3189135

********************************************************************************
*
**# 	Define Output Options 
*
********************************************************************************

* 	Graphing Options: 

set 		scheme s1color

graph set 	window fontface Times

graph set 	eps fontface Times

* 	Table Options: 

# d ; 

gl 	tab_optns	
		label varlabels(`e(labels)') modelwidth(8) varwidth(18) collabels(none) 
		nonotes cells((b(star fmt(%9.3f))) (se(fmt(%9.3f)par)) onecell) 
		starlevels(+ 0.1 * 0.05 ** 0.01 *** 0.001) r2 ;
	
# d cr

********************************************************************************
*
**# 	Define Estimation Globals
*
********************************************************************************

	* 	cntrls		: Controls
	* 	hdfe_opts	: FEs and Cluster Vars 

# d ; 

gl 	cntrls		
		i.white c.age i.prev_court_dv i.prev_court prev_court_num 
		c.charge_count i.judge_male c.judge_exp ;
	
gl 	hdfe_opts 	
		absorb(week_number year_court) vce(cluster def_id week_year) ;

# d cr

********************************************************************************
*
**# 	FIGURES.
*
********************************************************************************

	* Fig 2: 	Number of DV cases in Jail Docket by court specialization

include "${CODE}/fig2.do"

	* Fig 3: 	Distribution of Sentence Length by DV court vs General court

include "${CODE}/fig3.do"

	* Fig 4: 	Judge FE & excluding 1 Judge at a time 

include "${CODE}/fig4.do"

	* Fig 5: 	Total Number of monthly DV charges vs Assault charges

include "${CODE}/fig5.do"

	* Fig 6: 	Estimated Effects by Age

include "${CODE}/fig6.do"

	* Fig A3: 	Distribution of Defendants' Age 

include "${CODE}/figA3.do"

	* 	---------------------
	* 	Export graphs as pdf
	* 	---------------------

	cd "${OUTPUT}"

	local figs: dir "${OUTPUT}" files "*.gph" 

	local figs: subinstr local figs ".gph" "", all 

	foreach fig of local figs { 
		
		graph use `fig' 
		
		graph export `fig'.pdf, replace 
		
	} 

********************************************************************************
*
**# 	Tables.
*
********************************************************************************

	*	Table 1: 	Randomness of Assignment to DV Court for DV vs Other Cases

include "${CODE}/tab1.do"

	*	Table 2: 	How are DV Cases Processed in DV Court?
	
include "${CODE}/tab2.do"

	*	Table 3: 	Do DV Judges Make Different Decisions in DV Cases?
	
include "${CODE}/tab3.do"

	*	Table 4: 	Do DV Judges Make Different Decisions in VOP Cases?
	
include "${CODE}/tab4.do"

	* 	Table 5: 	Do DV Judges Make Different Decisions in Assault Cases?
		
include "${CODE}/tab5.do"

	* 	Table 6: 	Who is Convicted in DV Court?

include "${CODE}/tab6.do"

	* 	Table 7: 	Does DV Court Reduce Re-Victimization?
	
include "${CODE}/tab7.do"

	* 	Table 8: 	Does DV Court Reduce Future CJ Contact for Defendants?
	
include "${CODE}/tab8.do"

	* 	Table 9: 	Post Case Outcomes, by Court Assignment & Dismissal

include "${CODE}/tab9.do"

	* 	Table A3: 	Do DV Judges Make Different Decisions in DV Cases?
	* 				Incarceration and Sentence Length Conditional on Conviction
	
include "${CODE}/tabA3.do"

	* 	Table A4: 	Does DV Court Reduce Future Criminal Contact for Defendants?
	*				Re-Offending Conditional on Conviction
	
include "${CODE}/tabA4.do"

********************************************************************************
*   End of File
********************************************************************************

display _newline _dup(80) "=" _newline "DONE: `c(current_time)'" ///
	_newline _dup(80) "="

exit
